<script setup>
import { ref } from 'vue'

// 定义当前进度值，控制进度的宽度
const progress = ref(40) // 当前进度百分比

// 定义进度点的位置和文本内容
const progressPoints = ref([
  { position: 0, text: '1人', icon: 'https://via.placeholder.com/20' },
  { position: 20, text: '2人', icon: 'https://via.placeholder.com/20' },
  { position: 40, text: '3人', icon: 'https://via.placeholder.com/20' },
  { position: 60, text: '4人', icon: 'https://via.placeholder.com/20' },
  { position: 80, text: '5人', icon: 'https://via.placeholder.com/20' },
])

// 增加进度的函数
const increaseProgress = () => {
  if (progress.value < 100) {
    progress.value += 10
  }
}
</script>

<template>
  <div class="view-bs">
    <!-- 进度条背景 -->
    <div class="progress-bar">
      <div class="progress" :style="{ width: `${progress}%` }"></div>
    </div>
    <!-- 进度条上的标记点 -->
    <div class="progress-labels">
      <div
        v-for="(item, index) in progressPoints"
        :key="index"
        class="label-item"
        :style="{ left: `${item.position}%` }"
      >
        <!-- 图标放在上方 -->
        <img class="icon" :src="item.icon" alt="icon" />
        <div class="label-text">{{ item.text }}</div>
      </div>
    </div>

    <!-- 按钮用来增加进度 -->
    <button @click="increaseProgress" class="increase-btn">增加进度</button>
  </div>
</template>

<style scoped>
.view-bs {
  width: 100%; /* 容器宽度设置为 100% */
  max-width: 800px; /* 最大宽度 */
  padding: 20px;
  height: 400px;
  background: #de3c26; /* 背景颜色 */
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden; /* 防止溢出 */
}

/* 进度条背景 */
.progress-bar {
  display: flex;
  width: 100%;
  height: 20px;
  background-color: #e0e0e0; /* 浅灰色背景 */
  border-radius: 10px;
  position: relative;
  margin-bottom: 20px;
}

/* 进度条前景 */
.progress {
  height: 100%;
  background-color: #ff6b6b; /* 红色 */
  border-radius: 10px;
  position: absolute;
}

/* 进度点容器 */
.progress-labels {
  width: 100%;
  display: flex;
  flex-wrap: wrap; /* 允许换行 */
  justify-content: space-between;
  position: relative;
  margin-top: -30px; /* 调整标签和进度条的相对位置 */
}

/* 单个标记点 */
.label-item {
  position: absolute;
  text-align: center;
  width: 50px; /* 限制每个标签的宽度 */
}

.icon {
  width: 20px;
  height: 20px;
  margin-bottom: 5px; /* 图标与文字之间的间距 */
}

.label-text {
  font-size: 12px;
  color: #333;
  margin-top: 5px; /* 文字与图标之间的间距 */
}

/* 按钮样式 */
.increase-btn {
  padding: 10px 20px;
  background-color: #ff6b6b; /* 与进度条前景颜色一致 */
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.3s;
}

.increase-btn:hover {
  background-color: #e55b5b;
}
</style>
